//
// Created by Administrator on 2023/11/20.
//
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

const int N = 1e5 + 10;

struct Range {
    int l, r;

    bool operator<(const Range &W) const {
        return l < W.l;
    }
} range[N];

int main() {
    int n;
    cin >> n;
    priority_queue<int, vector<int>, greater<int>> min_heap;

    for (int i = 0; i < n; ++i) {
        cin >> range[i].l >> range[i].r;
        min_heap.push(range[i].r);
    }
    sort(range, range + n);

    for (int i = 0; i < n; i ++ )
    {

        if (min_heap.empty() || min_heap.top() >= range[i].l){
            min_heap.push(range[i].r);
        }
        else {
            min_heap.pop();
            min_heap.push(range[i].r);
        }
    }
    cout<<min_heap.size();
}
